var e = function (e) {
    return (e = e.toString())[1] ? e : "0".concat(e);
  },
  t = "https://ticket.sxd.cn/api-api/app/clientHelper",
  n = "https://ticket.sxd.cn/api-guide/app/clientHelper",
  o = function e(n, o) {
    return new Promise(function (a, r) {
      var c = wx.getStorageSync("token");
      wx.request({
        url: t + n,
        method: "post",
        header: { "content-type": "application/json", Authorization: c || "" },
        data: o,
        success: function (t) {
          return 403 == t.data.code
            ? (i(),
              void setTimeout(function () {
                a(e(n, o));
              }, 1e3))
            : 500 != t.data.code || "/pass/threeWayLogin/sxd" != n
              ? 0 != t.data.code
                ? ((t.msg || t.data.msg) &&
                    wx.showModal({
                      title:
                        0 == wx.getStorageSync("language")
                          ? "提示"
                          : "Reminder",
                      content: t.msg || t.data.msg,
                      showCancel: !1,
                      confirmText:
                        0 == wx.getStorageSync("language") ? "确定" : "Confirm",
                    }),
                  void r(t.data))
                : void a(t.data)
              : void wx.navigateTo({
                  url: "/pages/mine-index/login/index?redirectUrl=".concat(
                    encodeURIComponent("plugin://order/index-page"),
                    "&type=4",
                  ),
                });
        },
        fail: function (e) {},
      });
    });
  },
  a = function e(n, o, a) {
    return new Promise(function (r, c) {
      var d = wx.getStorageSync("token");
      wx.request({
        url: t + n,
        method: "get",
        header: { "content-type": "application/json", Authorization: d || "" },
        responseType: a || "",
        data: o,
        success: function (t) {
          return (
            console.log(t, "resresresres"),
            403 == t.data.code
              ? (i(),
                void setTimeout(function () {
                  r(e(n, o));
                }, 1e3))
              : a && 200 == t.statusCode
                ? void r(t)
                : 0 != t.data.code
                  ? (console.log(123456),
                    wx.showModal({
                      title: "提示",
                      content: t.msg || t.data.msg,
                      showCancel: !1,
                    }),
                    !1)
                  : void r(t.data)
          );
        },
        fail: function (e) {},
      });
    });
  };
function i() {
  var e = wx.getStorageSync("skey"),
    n = {
      appNo: "wx393d60d93f70599c",
      openId: requireMiniProgram().getOpenId(),
      configType: 1,
      loginType: 2,
      accessToken: e,
    };
  wx.request({
    url: t + "/pass/threeWayLogin/sxd",
    method: "post",
    header: { "content-type": "application/json" },
    data: n,
    success: function (e) {
      var t = e.data;
      if (0 == t.code) {
        if (null == t.uid)
          return void wx.navigateTo({
            url: "/pages/mine-index/login/index?redirectUrl=".concat(
              encodeURIComponent("plugin://order/index-page"),
              "&type=4",
            ),
          });
        wx.setStorageSync("token", t.token),
          wx.setStorageSync("openId", t.openId),
          wx.setStorageSync("telphoneNumber", t.contactsPhone),
          wx.setStorageSync("museumMerchant", t.museumMerchant),
          wx.setStorageSync("merchantNo", t.museumMerchant.merchantNo);
      } else {
        if (500 == t.code)
          return void wx.navigateTo({
            url: "/pages/mine-index/login/index?redirectUrl=".concat(
              encodeURIComponent("plugin://order/index-page"),
              "&type=4",
            ),
          });
        wx.showModal({
          title: "提示",
          content: t.msg || t.data.msg,
          showCancel: !1,
        });
      }
    },
  });
}
module.exports = {
  formatTime: function (t) {
    var n = t.getFullYear(),
      o = t.getMonth() + 1,
      a = t.getDate(),
      i = t.getHours(),
      r = t.getMinutes(),
      c = t.getSeconds();
    return ""
      .concat([n, o, a].map(e).join("/"), " ")
      .concat([i, r, c].map(e).join(":"));
  },
  post_form: o,
  get_form: a,
  post_guide_form: function (e, t) {
    return new Promise(function (a, r) {
      var c = wx.getStorageSync("token");
      wx.request({
        url: n + e,
        method: "post",
        header: { "content-type": "application/json", Authorization: c || "" },
        data: t,
        success: function (n) {
          return 403 == n.data.code
            ? (i(),
              void setTimeout(function () {
                a(o(e, t));
              }, 1e3))
            : 500 != n.data.code || "/pass/threeWayLogin/sxd" != e
              ? 0 != n.data.code
                ? ((n.msg || n.data.msg) &&
                    wx.showModal({
                      title: "提示",
                      content: n.msg || n.data.msg,
                      showCancel: !1,
                    }),
                  void r(n.data))
                : void a(n.data)
              : void wx.navigateTo({
                  url: "/pages/mine-index/login/index?redirectUrl=".concat(
                    encodeURIComponent("plugin://order/index-page"),
                    "&type=4",
                  ),
                });
        },
        fail: function (e) {},
      });
    });
  },
  get_guide_form: function (e, t) {
    return new Promise(function (o, r) {
      var c = wx.getStorageSync("token");
      wx.request({
        url: n + e,
        method: "get",
        header: { "content-type": "application/json", Authorization: c || "" },
        data: t,
        success: function (n) {
          return 403 == n.data.code
            ? (i(),
              void setTimeout(function () {
                o(a(e, t));
              }, 1e3))
            : 0 != n.data.code
              ? (wx.showModal({
                  title: "提示",
                  content: n.msg || n.data.msg,
                  showCancel: !1,
                }),
                !1)
              : void o(n.data);
        },
        fail: function (e) {},
      });
    });
  },
  Baseurl: t,
  CmsBaseUrl: "https://ticket.sxd.cn/api-cms/file/",
};
